import {reqGoodsInfo} from '../api'
import {reqAddOrUpdateShopCart} from '../api'
import {getUUID} from '../utils/uuid_token'
const state={
    getGoodsInfo:{},
    uuid_token:getUUID()
    // addOrUpdateShopCart:{}
}
const mutations={
    GETGOODINFO(state,getGoodsInfo){
        state.getGoodsInfo=getGoodsInfo
    },
    // ADD(state,addOrUpdateShopCart){
    //     state.addOrUpdateShopCart=addOrUpdateShopCart
    // }

}
const actions={
   async getGoodsInfo({commit},skuId){
        let {data}=await reqGoodsInfo(skuId)
        // console.log(data);
        if(data.code==200){
            commit('GETGOODINFO',data)
        }
    },
    async addOrUpdateShopCart({commit},{skuId,skuNum}){
        let {data}= await reqAddOrUpdateShopCart(skuId,skuNum)
        // console.log(data);
        // if(result.code==200){
        //     commit('ADD',result.data)
        // }
        if(data.code==200){
            return "ok"
        }else {
            return Promise.reject(new Error('false'));
        }
        },
}
const getters={
    categoryView(state){
        return state.getGoodsInfo.data.categoryView||{};
    },
    skuInfo(state){
        return state.getGoodsInfo.data.skuInfo||{};
    },
    spuSaleAttrList(state){
        return state.getGoodsInfo.data.spuSaleAttrList||{};
    }
}
export default {
    state,
    mutations,
    actions,
    getters
}